/***** Lobxxx Translate Finished ******/
/*
 * Copyright (c) 1999, 2003, Oracle and/or its affiliates. All rights reserved.
 * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 */

package javax.sound.sampled;

/**
 * The <code>LineEvent</code> class encapsulates information that a line
 * sends its listeners whenever the line opens, closes, starts, or stops.
 * Each of these four state changes is represented by a corresponding
 * type of event.  A listener receives the event as a parameter to its
 * {@link LineListener#update update} method.  By querying the event,
 * the listener can learn the type of event, the line responsible for
 * the event, and how much data the line had processed when the event occurred.
 *
 * <p>Although this class implements Serializable, attempts to
 * serialize a <code>LineEvent</code> object will fail.
 *
 * <p>
 *  <code> LineEvent </code>类封装了当行打开,关闭,启动或停止时,行发送其监听器的信息。这四个状态变化中的每一个由相应类型的事件表示。
 * 侦听器接收事件作为其{@link LineListener#update update}方法的参数。通过查询事件,侦听器可以了解事件的类型,负责事件的行以及当事件发生时行处理了多少数据。
 * 
 *  <p>虽然这个类实现了Serializable,但是尝试序列化一个<code> LineEvent </code>对象将会失败。
 * 
 * 
 * @author Kara Kytle
 *
 * @see Line
 * @see LineListener#update
 * @since 1.3
 *
 * @serial exclude
 */
public class LineEvent extends java.util.EventObject {

    // INSTANCE VARIABLES

    /**
     * The kind of line event (<code>OPEN</code>, <code>CLOSE</code>,
     * <code>START</code>, or <code>STOP</code>).
     * <p>
     *  线事件的类型(<code> OPEN </code>,<code> CLOSE </code>,<code> START </code>或<code> STOP </code>)。
     * 
     * 
     * @see #getType
     * @serial
     */
    private final Type type;

    /**
     * The media position when the event occurred, expressed in sample frames.
     * Note that this field is only relevant to certain events generated by
     * data lines, such as <code>START</code> and <code>STOP</code>.  For
     * events generated by lines that do not count sample frames, and for any
     * other events for which this value is not known, the position value
     * should be {@link AudioSystem#NOT_SPECIFIED}.
     * <p>
     *  事件发生时的媒体位置,以样本帧表示。请注意,此字段仅与数据行生成的某些事件相关,例如<code> START </code>和<code> STOP </code>。
     * 对于不计算样本帧的行生成的事件,以及对于未知此值的任何其他事件,位置值应为{@link AudioSystem#NOT_SPECIFIED}。
     * 
     * 
     * @serial
     * @see #getFramePosition
     */
    private final long position;


    /**
     * Constructs a new event of the specified type, originating from the specified line.
     * <p>
     *  构造指定类型的新事件,源自指定的行。
     * 
     * 
     * @param line the source of this event
     * @param type the event type (<code>OPEN</code>, <code>CLOSE</code>, <code>START</code>, or <code>STOP</code>)
     * @param position the number of sample frames that the line had already processed when the event occurred,
     * or {@link AudioSystem#NOT_SPECIFIED}
     *
     * @throws IllegalArgumentException if <code>line</code> is
     * <code>null</code>.
     */
    public LineEvent(Line line, Type type, long position) {

        super(line);
        this.type = type;
        this.position = position;
    }

    /**
     * Obtains the audio line that is the source of this event.
     * <p>
     *  获取作为此事件源的音频线。
     * 
     * 
     * @return the line responsible for this event
     */
    public final Line getLine() {

        return (Line)getSource();
    }


    /**
     * Obtains the event's type.
     * <p>
     *  获取事件的类型。
     * 
     * 
     * @return this event's type ({@link Type#OPEN}, {@link Type#CLOSE},
     * {@link Type#START}, or {@link Type#STOP})
     */
    public final Type getType() {

        return type;
    }

    /**
     * Obtains the position in the line's audio data when the event occurred, expressed in sample frames.
     * For example, if a source line had already played back 14 sample frames at the time it was
     * paused, the pause event would report the line's position as 14.  The next frame to be processed
     * would be frame number 14 using zero-based numbering, or 15 using one-based numbering.
     * <p>
     * Note that this field is relevant only to certain events generated by
     * data lines, such as <code>START</code> and <code>STOP</code>.  For
     * events generated by lines that do not count sample frames, and for any
     * other events for which this value is not known, the position value
     * should be {@link AudioSystem#NOT_SPECIFIED}.
     *
     * <p>
     * 在事件发生时获取行的音频数据中的位置,以样本帧表示。
     * 例如,如果源行已经在暂停时播放了14个采样帧,则暂停事件将报告该行的位置为14.要处理的下一帧将是使用基于零的编号的帧号14,或者15使用基于1的编号。
     * <p>
     *  请注意,此字段仅与数据行生成的某些事件相关,例如<code> START </code>和<code> STOP </code>。
     * 对于不计算样本帧的行生成的事件,以及对于未知此值的任何其他事件,位置值应为{@link AudioSystem#NOT_SPECIFIED}。
     * 
     * 
     * @return the line's position as a sample frame number
     */
    /*
     * $$kk: 04.20.99: note to myself: should make sure our implementation is consistent with this.
     * which is a reasonable definition....
     * <p>
     *  $$ kk：04.20.99：注意自己：应该确保我们的实现与此一致。这是一个合理的定义....
     * 
     */
    public final long getFramePosition() {

        return position;
    }

    /**
     * Obtains a string representation of the event.  The contents of the string may vary
     * between implementations of Java Sound.
     * <p>
     *  获取事件的字符串表示形式。字符串的内容可能随Java Sound的实现而有所不同。
     * 
     * 
     * @return a string describing the event.
     */
    public String toString() {
        String sType = "";
        if (type != null) sType = type.toString()+" ";
        String sLine;
        if (getLine() == null) {
            sLine = "null";
        } else {
            sLine = getLine().toString();
        }
        return new String(sType + "event from line " + sLine);
    }


    /**
     * The LineEvent.Type inner class identifies what kind of event occurred on a line.
     * Static instances are provided for the common types (OPEN, CLOSE, START, and STOP).
     *
     * <p>
     *  LineEvent.Type内部类标识在一行上发生了什么类型的事件。为常见类型提供静态实例(OPEN,CLOSE,START和STOP)。
     * 
     * 
     * @see LineEvent#getType()
     */
    public static class Type {


        /**
         * Type name.
         * <p>
         *  类型名称。
         * 
         */
        // $$kk: 03.25.99: why can't this be final??
        private /*final*/ String name;

        /**
         * Constructs a new event type.
         * <p>
         *  / **构造新的事件类型。
         * 
         * 
         * @param name name of the type
         */
        protected Type(String name) {
            this.name = name;
        }


        //$$fb 2002-11-26: fix for 4695001: SPEC: description of equals() method contains typo
        /**
         * Indicates whether the specified object is equal to this event type,
         * returning <code>true</code> if the objects are identical.
         * <p>
         *  指示指定的对象是否等于此事件类型,如果对象相同,则返回<code> true </code>。
         * 
         * 
         * @param obj the reference object with which to compare
         * @return <code>true</code> if this event type is the same as
         * <code>obj</code>; <code>false</code> otherwise
         */
        public final boolean equals(Object obj) {
            return super.equals(obj);
        }


        /**
         * Finalizes the hashcode method.
         * <p>
         *  完成哈希码方法。
         * 
         */
        public final int hashCode() {
            return super.hashCode();
        }


        /**
         * Returns the type name as the string representation.
         * <p>
         *  返回类型名称作为字符串表示形式。
         * 
         */
        public String toString() {
            return name;
        }


        // LINE EVENT TYPE DEFINES

        /**
         * A type of event that is sent when a line opens, reserving system
         * resources for itself.
         * <p>
         *  线路打开时发送的事件类型,为自己保留系统资源。
         * 
         * 
         * @see #CLOSE
         * @see Line#open
         */
        public static final Type OPEN   = new Type("Open");


        /**
         * A type of event that is sent when a line closes, freeing the system
         * resources it had obtained when it was opened.
         * <p>
         * 线路关闭时发送的事件类型,释放它在打开时获得的系统资源。
         * 
         * 
         * @see #OPEN
         * @see Line#close
         */
        public static final Type CLOSE  = new Type("Close");


        /**
         * A type of event that is sent when a line begins to engage in active
         * input or output of audio data in response to a
         * {@link DataLine#start start} request.
         * <p>
         *  当线路开始响应{@link DataLine#start start}请求进行音频数据的活动输入或输出时发送的事件类型。
         * 
         * 
         * @see #STOP
         * @see DataLine#start
         */
        public static final Type START  = new Type("Start");


        /**
         * A type of event that is sent when a line ceases active input or output
         * of audio data in response to a {@link DataLine#stop stop} request,
         * or because the end of media has been reached.
         * <p>
         *  当线路响应{@link DataLine#stop stop}请求,或因为已到达媒体结束时,停止音频数据的活动输入或输出时发送的事件类型。
         * 
         * 
         * @see #START
         * @see DataLine#stop
         */
        public static final Type STOP   = new Type("Stop");


        /**
         * A type of event that is sent when a line ceases to engage in active
         * input or output of audio data because the end of media has been reached.
         * <p>
         *  当线路停止进行音频数据的活动输入或输出时发送的事件类型,因为已到达媒体结束。
         * 
         */
        /*
         * ISSUE: we may want to get rid of this.  Is JavaSound
         * responsible for reporting this??
         *
         * [If it's decided to keep this API, the docs will need to be updated to include mention
         * of EOM events elsewhere.]
         * <p>
         *  问题：我们可能想要摆脱这一点。是JavaSound负责报告这个?
         * 
         *  [如果决定保留此API,则需要更新文档,以便在其他地方提及EOM事件。]
         * 
         */
        //public static final Type EOM  = new Type("EOM");


        /**
         * A type of event that is sent when a line begins to engage in active
         * input or output of audio data.  Examples of when this happens are
         * when a source line begins or resumes writing data to its mixer, and
         * when a target line begins or resumes reading data from its mixer.
         * <p>
         *  线路开始进行音频数据的有效输入或输出时发送的事件类型。当发生这种情况时,当源线开始或恢复向其混合器写入数据时,以及当目标线开始或恢复从其混合器读取数据时。
         * 
         * 
         * @see #STOP
         * @see SourceDataLine#write
         * @see TargetDataLine#read
         * @see DataLine#start
         */
        //public static final Type ACTIVE       = new Type("ACTIVE");


        /**
         * A type of event that is sent when a line ceases active input or output
         * of audio data.
         * <p>
         *  当线路停止音频数据的活动输入或输出时发送的事件类型。
         * 
         * @see #START
         * @see DataLine#stop
         */
        //public static final Type INACTIVE     = new Type("INACTIVE");

    } // class Type

} // class LineEvent
